/* Layout */
import Layout from '@/layout'
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: {
          title: '首页',
          icon: 'dashboard',
          noCache: true,
          affix: true
        }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

// 初始化路由实例
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    // 默认路由为上面声明的静态路由表
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// 重置路由的方法，重新调用上面的初始化路由方法
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
export const asyncRoutes = [
  // 广告编辑
  {
    path: '/add_editor',
    component: Layout,
    redirect: '/add-editor/add-link',
    name: 'addEditer',
    meta: { title: '广告编辑', icon: 'form', roles: ['root'], id: 22 },
    children: [
      {
        path: 'add_banner',
        name: 'addLink',
        component: () => import('@/views/add-editor/add-banner'),
        meta: { title: '轮播图', id: 23 }
      },
      {
        path: 'add_link',
        name: 'addLink',
        component: () => import('@/views/add-editor/add-link'),
        meta: { title: '链接区', id: 24 }
      },
      {
        path: 'mall_picture',
        name: 'MallPicture',
        component: () => import('@/views/add-editor/add-mall'),
        meta: { title: '商城图片魔方', id: 25 }
      }
      // {
      //   path: "add_place",
      //   name: "add-place",
      //   component: () => import("@/views/add-editor/add-place"),
      //   meta: { title: "广告位" }
      // }
      // {
      //   path: "user_defined",
      //   name: "userDefined",
      //   component: () => import("@/views/add-editor/user-defined"),
      //   meta: { title: "自定义页面" }
      // }
    ]
  },
  {
    path: '/good-mng',
    component: Layout,
    redirect: '/good-mng/normal-good',
    name: 'GoodMng',
    meta: { title: '商品管理', icon: 'form', roles: ['root'], id: 14 },
    children: [
      {
        path: 'normal-goods',
        name: 'NormalGoods',
        component: () => import('@/views/good-mng/normal-good'),
        meta: { title: '商品列表', id: 15 }
      },
      {
        path: 'good-class',
        name: 'GoodClass',
        component: () => import('@/views/good-mng/good-class'),
        meta: { title: '商品分类', id: 16 }
      },
      {
        path: 'prop-mng',
        name: 'PropMng',
        component: () => import('@/views/good-mng/prop-mng'),
        meta: { title: '规格管理', id: 17 }
      },
      {
        path: 'brand-mng',
        name: 'BrandMng',
        component: () => import('@/views/good-mng/brand-mng'),
        meta: { title: '品牌管理', id: 18 }
      },
      {
        path: 'inventory-mng',
        name: 'InventoryMng',
        component: () => import('@/views/good-mng/inventory-mng'),
        meta: { title: '库存管理', id: 19 }
      },
      {
        path: 'comment-mng',
        name: 'CommentMng',
        component: () => import('@/views/good-mng/comment-mng'),
        meta: { title: '评价管理', id: 20 }
      }
    ]
  },
  // 积分规则
  {
    path: '/integral',
    component: Layout,
    name: 'Integral',
    redirect: '/integral/integral-rules',
    meta: { title: '积分规则', id: 2, icon: 'form', roles: ['root'] },
    children: [
      {
        path: 'integral-rules',
        name: 'IntegralRules',
        component: () => import('@/views/integral-rules/index.vue'),
        meta: { title: '积分规则', id: 2, roles: ['root'] }
      }
    ]
  },
  // 用户管理
  {
    path: '/normal-user',
    component: Layout,
    name: 'ordinaryUser',
    redirect: '/normal-user/ordinary-user',
    meta: { title: '用户管理', id: 2, icon: 'form', roles: ['root'] },
    children: [
      {
        path: 'ordinary-user',
        name: 'User',
        component: () => import('@/views/user-vip-mng/ordinary-user'),
        meta: { title: '用户管理', id: 2, roles: ['root'] }
      }
    ]
  },
  {
    path: '/user-mng',
    component: Layout,
    redirect: '/user-mng/ordinary-user',
    name: 'userMng',
    meta: {
      title: 'VIP管理',
      icon: 'form',
      roles: ['root'],
      id: 1
    },
    children: [
      {
        path: 'vip-goods',
        name: 'VipGoods',
        component: () => import('@/views/user-vip-mng/vip-goods'),
        meta: { title: 'VIP卡', id: 16 }
      },
      {
        path: 'ordinary-vip',
        name: 'ordinaryVip',
        component: () => import('@/views/user-vip-mng/ordinary-vip'),
        meta: { title: 'VIP用户', id: 3 }
      },
      {
        path: 'vip-order',
        name: 'VipOrder',
        component: () => import('@/views/user-vip-mng/vip-order'),
        meta: { title: 'VIP卡购买记录', roles: ['root'], id: 8 }
      },
      {
        path: 'revenue-rank',
        name: 'ReveneRank',
        component: () => import('@/views/user-vip-mng/revenue-rank'),
        meta: { title: '分佣排行', roles: ['root'], id: 99 }
      },
      {
        path: 'commission',
        name: 'Commission',
        component: () => import('@/views/user-vip-mng/commission'),
        meta: { title: '商品佣金设置', roles: ['root'], id: 99 }
      },
      {
        path: 'vip-poster',
        name: 'VipPoster',
        component: () => import('@/views/user-vip-mng/vip-poster'),
        meta: { title: 'VIP规则权益海报', id: 4 }
      },
      {
        path: 'vip-teacher',
        name: 'VipTeacher',
        component: () => import('@/views/user-vip-mng/vip-teacher'),
        meta: { title: '官方微信', id: 5 }
      },
      {
        path: 'college-mng',
        name: 'collegeMng',
        component: () => import('@/views/user-vip-mng/college-mng.vue'),
        meta: { title: 'VIP学院文章', id: 44 }
      },
      {
        path: 'share-poster',
        name: 'SharePoster',
        component: () => import('@/views/user-vip-mng/share-poster.vue'),
        meta: { title: '分享海报', id: 44 }
      }
      // {
      //   path: "vip-apply",
      //   name: "VipApply",
      //   component: () => import("@/views/user-vip-mng/vip-apply"),
      //   meta: { title: "会员审核" }
      // },
    ]
  },
  {
    path: '/order-mng',
    component: Layout,
    redirect: '/order-mng/normal-order',
    name: 'OrderMng',
    meta: { title: '订单管理', icon: 'form', id: 6 },
    children: [
      {
        path: 'normal-order',
        name: 'NormalOrder',
        component: () => import('@/views/order-mng/normal-order'),
        meta: { title: '商品订单', id: 7 }
      },
      {
        path: 'after-sale-order',
        name: 'AfterSaleOrder',
        component: () => import('@/views/order-mng/after-sale-order'),
        meta: { title: '售后订单', id: 9 }
      }
    ]
  },
  // {
  //   path: '/agent-mng',
  //   component: Layout,
  //   redirect: '/agent-mng/agent-list',
  //   name: 'AgentMng',
  //   meta: { title: '代理管理', icon: 'form', roles: ['root'], id: 10 },
  //   children: [
  //     {
  //       path: 'agent-list',
  //       name: 'AgentList',
  //       component: () => import('@/views/agent-mng/agent-list'),
  //       meta: { title: '代理列表', id: 11 }
  //     },
  //     {
  //       path: 'earning-detail',
  //       name: 'EarningDetail',
  //       component: () => import('@/views/agent-mng/earning-detail'),
  //       meta: { title: '收益详情', id: 12 },
  //       hidden: true
  //     },
  //     {
  //       path: 'agent-apply',
  //       name: 'AgentApply',
  //       component: () => import('@/views/agent-mng/agent-apply'),
  //       meta: { title: '代理申请', id: 13 }
  //     }
  //   ]
  // },
  {
    path: '/promotion-mng',
    component: Layout,
    redirect: '/promotion-mng/coupon',
    name: 'PromotionMng',
    meta: { title: '促销管理', icon: 'form', roles: ['root'], id: 48 },
    children: [
      {
        path: 'coupon',
        name: 'Coupon',
        component: () => import('@/views/promotion-mng/coupon'),
        meta: { title: '优惠券', id: 21 }
      }
    ]
  },
  // 头条管理
  // {
  //   path: '/headerline-news',
  //   component: Layout,
  //   redirect: '/headerline-news/dynamics-headerline',
  //   name: 'headerlineNews',
  //   meta: { title: '头条管理', icon: 'form', roles: ['root'], id: 26 },
  //   children: [
  //     {
  //       path: 'dynamics-headerline',
  //       name: 'dynamicsHeaderline',
  //       component: () =>
  //                import('@/views/headerline-news/dynamics-headerline'),
  //       meta: { title: '动态头条', id: 27 }
  //     }
  //     // {
  //     //   path: "shopping-headerline",
  //     //   name: "shoppingHeaderline",
  //     //   component: () => import("@/views/headerline-news/shopping-headerline"),
  //     //   meta: { title: "商城头条" }
  //     // }
  //   ]
  // },
  // 退款订单
  //  {
  //    path: "/refund-trade",
  //    component: Layout,
  //    redirect: "/refund-trade/remit",
  //    name: "refundTrade",
  //    meta: { title: "退款订单", icon: "form", roles: ["root"], id: 28 },
  //    children: [
  //      {
  //        path: "remit",
  //        name: "remit",
  //        component: () => import("@/views/refundTrade/remit"),
  //        meta: { title: "待打款", id: 29 }
  //      },
  //      {
  //        path: "remitted",
  //        name: "remitted",
  //        component: () => import("@/views/refundTrade/remitted"),
  //        meta: { title: "已打款", id: 30 }
  //      }
  //    ]
  //  },
  // {
  //   path: '/express-mng',
  //   component: Layout,
  //   redirect: '/express-mng/index',
  //   name: 'ExpressMng',
  //   meta: { title: '物流管理', icon: 'form', roles: ['root'], id: 31 },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'ExpressMngIndex',
  //       component: () => import('@/views/express-mng/'),
  //       meta: { title: '物流管理', id: 32 }
  //     }
  //   ]
  // },
  // 提现管理
  {
    path: '/draw-mng',
    component: Layout,
    redirect: '/draw-mng/pending',
    name: 'draw-mng',
    meta: { title: '提现管理', icon: 'form', roles: ['root'], id: 33 },
    children: [
      {
        path: 'pending',
        name: 'pending',
        component: () => import('@/views/draw-mng/pending'),
        meta: { title: '待处理', id: 34 }
      },
      {
        path: 'play-game',
        name: 'play-game',
        component: () => import('@/views/draw-mng/playGame'),
        meta: { title: '打款中', id: 35 }
      },
      {
        path: 'have-money',
        name: 'have-money',
        component: () => import('@/views/draw-mng/haveMoney'),
        meta: { title: '已打款', id: 36 }
      },
      {
        path: 'refused',
        name: 'refused',
        component: () => import('@/views/draw-mng/refused'),
        meta: { title: '已拒绝', id: 37 }
      },
      // {
      //   path: "draw-rule",
      //   name: "draw-rule",
      //   component: () => import("@/views/draw-mng/drawingsRule"),
      //   meta: { title: "提现规则" }
      // },
      {
        path: 'apply-mng',
        name: 'WithdrawApplyMng',
        component: () => import('@/views/draw-mng/apply-mng'),
        meta: { title: '提现认证', id: 38 }
      }
    ]
  },
  // 平台设置
  {
    path: '/platform',
    component: Layout,
    redirect: '/platform-content',
    name: 'Platform',
    meta: { title: '平台设置', icon: 'form', roles: ['root'], id: 40 },
    children: [
      {
        path: 'platform-content',
        name: 'PlatformContent',
        component: () => import('@/views/platform-setting/platform-content.vue'),
        meta: { title: '平台内容', id: 42 }
      },
      {
        path: 'platform-setting',
        name: 'PlatformSetting',
        component: () => import('@/views/platform-setting/send-news.vue'),
        meta: { title: '消息推送', id: 41 }
      },
      {
        path: 'express',
        name: 'ExpressMngIndex',
        component: () => import('@/views/platform-setting/express.vue'),
        meta: { title: '物流设置', id: 33 }
      },
      {
        path: 'protocol',
        name: 'Protocol',
        component: () => import('@/views/platform-setting/protocol.vue'),
        meta: { title: '协议设置', id: 34 }
      },
      {
        path: 'payment-settings',
        name: 'PaymentSettings',
        component: () => import('@/views/platform-setting/payment-settings.vue'),
        meta: { title: '支付配置', id: 35 }
      },
      {
        path: 'message-settings',
        name: 'MessageSettings',
        component: () => import('@/views/platform-setting/message-settings.vue'),
        meta: { title: '短信配置', id: 36 }
      }
    ]
  },
  // {
  //   path: '/page-setting',
  //   component: Layout,
  //   redirect: '/page-setting/setting',
  //   name: 'pageSetting',
  //   meta: { title: '页面设置', icon: 'form', roles: ['root'], id: 39 },
  //   children: [
  //     {
  //       path: 'setting',
  //       name: 'setting',
  //       component: () => import('@/views/page-setting/'),
  //       meta: { title: '客服电话设置', id: 40 }
  //     }
  //   ]
  // },
  // 内容管理
  {
    path: '/content',
    component: Layout,
    redirect: '/content/content-mng',
    name: 'content',
    meta: { title: '视频管理', icon: 'form', roles: ['root'], id: 40 },
    children: [
      {
        path: 'dynamic-audit',
        name: 'DynamicAudit',
        component: () => import('@/views/dynamics/dynamic-audit.vue'),
        meta: { title: '视频审核', id: 41 }
      },
      {
        path: 'content-mng',
        name: 'contentMng',
        component: () => import('@/views/dynamics/contentMng'),
        meta: { title: '视频管理', id: 42 }
      },
      {
        path: 'dynamics-sort',
        name: 'dynamicsSort',
        component: () => import('@/views/dynamics/dynamicsSort'),
        meta: { title: '视频分类', id: 43 }
      },
      {
        path: 'article-mng',
        name: 'articleMng',
        component: () => import('@/views/dynamics/article-mng.vue'),
        meta: { title: '图文动态', id: 45 }
      }
      // {
      //   path: "sensitive-set",
      //   name: "sensitiveSet",
      //   component: () => import("@/views/dynamics/sensitiveSet"),
      //   meta: { title: "敏感词设置" }
      // }
    ]
  },
  {
    path: '/auth-nmg',
    component: Layout,
    redirect: 'index',
    name: 'AuthMng',
    meta: { title: '权限管理', icon: 'form', roles: ['root'], id: 46 },
    children: [
      {
        path: 'index',
        name: 'AuthMngIndex',
        component: () => import('@/views/auth-mng'),
        meta: { title: '权限管理', id: 47 }
      },
      {
        path: 'admin-edit',
        name: 'AdminEdit',
        component: () => import('@/views/auth-mng/admin-edit'),
        meta: { title: '编辑信息', id: 49 },
        hidden: true
      }
    ]
  },
  {
    disabled: true,
    path: '/earning-nmg',
    component: Layout,
    redirect: 'index',
    name: 'EarningMng',
    meta: { title: '收益管理', icon: 'form', roles: ['agent'] },
    children: [
      {
        disabled: true,
        path: 'index',
        name: 'EarningMngIndex',
        component: () => import('@/views/earning-mng'),
        meta: { title: '收益管理' }
      }
    ]
  },
  { disabled: true, path: '*', redirect: '/404', hidden: true }
]
